<html>
<head><meta charset="utf-8"><title>Portable code only used by some platforms · t-libs · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/index.html">t-libs</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Portable.20code.20only.20used.20by.20some.20platforms.html">Portable code only used by some platforms</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="231366535"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Portable%20code%20only%20used%20by%20some%20platforms/near/231366535" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> The 8472 <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Portable.20code.20only.20used.20by.20some.20platforms.html#231366535">(Mar 22 2021 at 19:05)</a>:</h4>
<p>Placing code in <code>std::sys_common</code> that is portable but only used by some platforms leads to unused/dead code warnings. Adding e.g <code>cfg(any(unix, wasi))</code> doesn't work because then tidy complains because <code>cfg</code>'d code should go into <code>std::sys</code>.</p>
<p>What's the right way to deal with this? <code>#[allow(dead_code)}</code> or a new cross platform  module under <code>std::sys</code>?</p>



<a name="231367097"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Portable%20code%20only%20used%20by%20some%20platforms/near/231367097" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mara <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Portable.20code.20only.20used.20by.20some.20platforms.html#231367097">(Mar 22 2021 at 19:09)</a>:</h4>
<p><span class="user-mention" data-user-id="330154">@The 8472</span> hm. we already have cfgs in sys_common. maybe tidy missed those?</p>



<a name="231367258"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Portable%20code%20only%20used%20by%20some%20platforms/near/231367258" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mara <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Portable.20code.20only.20used.20by.20some.20platforms.html#231367258">(Mar 22 2021 at 19:10)</a>:</h4>
<p>oh maybe it doesn't understand <code>cfg_if::cfg_if!</code> and accepts that in sys_common</p>



<a name="231367296"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Portable%20code%20only%20used%20by%20some%20platforms/near/231367296" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> The 8472 <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Portable.20code.20only.20used.20by.20some.20platforms.html#231367296">(Mar 22 2021 at 19:10)</a>:</h4>
<p>Yeah, there are some exceptions</p>
<div class="codehilite"><pre><span></span><code>    // Integration test for platform-specific run-time feature detection:
    &quot;library/std/tests/run-time-detect.rs&quot;,
    &quot;library/std/src/net/test.rs&quot;,
    &quot;library/std/src/net/addr&quot;,
    &quot;library/std/src/net/udp&quot;,
    &quot;library/std/src/sys_common/mod.rs&quot;,
    &quot;library/std/src/sys_common/net.rs&quot;,
    &quot;library/std/src/sys_common/backtrace.rs&quot;,
    &quot;library/std/src/sys_common/remutex.rs&quot;,
    &quot;library/std/src/sync/mutex.rs&quot;,
</code></pre></div>
<p>But I think they shouldn't be relied on... my addition to rwlock was probably in error.</p>



<a name="231367550"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Portable%20code%20only%20used%20by%20some%20platforms/near/231367550" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mara <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Portable.20code.20only.20used.20by.20some.20platforms.html#231367550">(Mar 22 2021 at 19:12)</a>:</h4>
<p>i think it's fine</p>



<a name="231367635"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Portable%20code%20only%20used%20by%20some%20platforms/near/231367635" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> The 8472 <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Portable.20code.20only.20used.20by.20some.20platforms.html#231367635">(Mar 22 2021 at 19:13)</a>:</h4>
<p>Well, I wanted to add another one that's not on the exception list that's why I'm asking.</p>



<a name="231367958"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Portable%20code%20only%20used%20by%20some%20platforms/near/231367958" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> The 8472 <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Portable.20code.20only.20used.20by.20some.20platforms.html#231367958">(Mar 22 2021 at 19:15)</a>:</h4>
<p>I'll pepper it with <code>#[allow(dead_code)]</code> for now, let's see what the reviewers say.</p>



<a name="231368330"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Portable%20code%20only%20used%20by%20some%20platforms/near/231368330" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mara <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Portable.20code.20only.20used.20by.20some.20platforms.html#231368330">(Mar 22 2021 at 19:17)</a>:</h4>
<p><span class="user-mention" data-user-id="330154">@The 8472</span> i'm fine with cfgs like those on StaticRWLock on new additions, even if that means adding another exception to tidy's list. the whole sys/sys_common/std split is pretty much non-existent anyway. any project towards splitting that will have much bigger issues to deal with than a few anti-dead_code cfgs.</p>



<a name="231368419"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Portable%20code%20only%20used%20by%20some%20platforms/near/231368419" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mara <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Portable.20code.20only.20used.20by.20some.20platforms.html#231368419">(Mar 22 2021 at 19:18)</a>:</h4>
<p>and if you go for <code>allow(dead_code)</code>, please make that <code>cfg_attr(..., allow(dead_code))</code>, so we still detect it if code becomes unused on all platforms.</p>



<a name="231368718"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Portable%20code%20only%20used%20by%20some%20platforms/near/231368718" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> The 8472 <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Portable.20code.20only.20used.20by.20some.20platforms.html#231368718">(Mar 22 2021 at 19:19)</a>:</h4>
<p>Great,  that makes the intent clearer</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>